import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './router/router'
import store from './store'
import axios from 'axios'
import {ToastPlugin, LoadingPlugin} from 'vux'
import VueAxios from 'vue-axios'
import './common/js/rem'
import './common/stylus/index.styl'
import './common/js/jsencryptKey'
import 'swiper/dist/css/swiper.css'
import '../static/css/reset.css'
import {routerMode} from "./common/js/env"
import VueAwesomeSwiper from 'vue-awesome-swiper'
import {TreeSelect} from 'vant'
import {List} from 'vant'
import {Cell} from 'vant'
import {Progress} from 'vant'
import {ImagePreview} from 'vant'
import {Checkbox, CheckboxGroup} from 'vant'

Vue.use(Checkbox).use(CheckboxGroup)
Vue.use(ImagePreview);
Vue.use(List);
Vue.use(TreeSelect);
Vue.use(Progress);
Vue.use(Cell);
Vue.use(ToastPlugin);
Vue.use(LoadingPlugin);
Vue.use(VueAxios, axios);
Vue.use(VueRouter);
Vue.use(VueAwesomeSwiper);
Vue.config.productionTip = false;
//axios发送跨域请求时，默认不携带cookie
// axios.defaults.withCredentials=true;

const router = new VueRouter({
  routes,
  // base:'/lanpin/',
  mode: routerMode,
});

const whiteList = ['/login', '/wxlogin', '/regist', '/forget', '/protocol', '/index/recruitlist', "/recruitdetail", '/referral', '/entryevaluate', '/entryevaluateedit', '/chaseevaluate', '/delevaluate', '/mine', '/error'];
router.beforeEach((to, form, next) => {
  /*路由变化修改title*/
  if (to.meta.title) {
    document.title = to.meta.title;
  }

  // ios端不能正确复制页面链接
  const agent = navigator.userAgent;
  const isiOS = !!agent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
  if (isiOS && (to.path !== location.pathname)) {
    location.assign(to.fullPath);
  } else {
    /*未登录拦截*/
    if (whiteList.indexOf(to.path) !== -1) {
      next();
    } else {
      if (sessionStorage.getItem("user_sign")) {
        next();
      } else {
        next({path: '/login'});
      }
    }
  }
});


new Vue({
  router,
  store,
}).$mount('#app');

